<?php

namespace App\Http\Controllers;

use App\Library\Requests\Base\IdRequest;
use App\Library\Requests\User\UserCompanyAddRequest;
use App\Library\Requests\User\UserEditRequest;
use App\Library\Service\UserService;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class UserController extends BaseController
{
    /**
     * @param UserService $service
     */
    public function __construct(UserService $service)
    {
        $this->service = $service;
    }

    /**
     * setAgent
     * @param IdRequest $request
     * @return JsonResponse
     */
    public function setAgent(IdRequest $request): JsonResponse
    {
        if ((int)config('app.superId') !== USERID) return fail();
        else return $this->service->setAgent($request);
    }

    /**
     * 审核状态信息
     * @return JsonResponse
     */
    public function auditInfo(): JsonResponse
    {
        return $this->service->auditInfo();
    }

    /**
     * info
     * @return JsonResponse
     */
    public function info(Request $request): JsonResponse
    {
        return $this->service->info($request);
    }

    /**
     * 编辑用户信息
     * @param UserEditRequest $request
     * @return JsonResponse
     * @throws Exception
     */
    public function edit(UserEditRequest $request): JsonResponse
    {
        return $this->service->edit($request);
    }

    /**
     * 退出登录
     * @return JsonResponse
     */
    public function logout(): JsonResponse
    {
        return $this->service->logout();
    }

    /**
     * companyAdd
     * @param UserCompanyAddRequest $request
     * @return JsonResponse
     */
    public function companyAdd(UserCompanyAddRequest $request): JsonResponse
    {
        return $this->service->companyAdd($request);
    }

    /**
     * companyInfo
     * @return JsonResponse
     */
    public function companyInfo(): JsonResponse
    {
        return $this->service->companyInfo();
    }

    /**
     * cache
     * @param int $id
     * @return JsonResponse
     */
    public function cache(int $id): JsonResponse
    {
        return $this->service->cache($id);
    }
}
